package org.jugile.restapi.domain;

import org.jugile.restapi.common.*;
import org.jugile.util.Node;

public class Type extends TypeBase implements org.jugile.util.IDO {

	public String resolveMimetype() {
		if (!empty(getMimetype())) return getMimetype();
		return "text/html";
	}
	
	public void parse(Node n) {
		setName(n.attr("name"));
		setMimetype(n.attr("mime-type"));
		setSuffix("."+getName());
		if (!empty(n.attr("suffix"))) setSuffix(n.attr("suffix"));
		if ("true".equals(n.attr("default"))) getApi().setDefaultType(this);
	}
	
	public Node toXml() {
		Node n = new Node("type");
		n.attr("name",getName());
		n.attr("suffix",getSuffix());
		n.attr("mime-type",getMimetype());
		if (getApi().getDefaultType().equals(this)) n.attr("default","true");
		return n;
	}

	
}